<?php 
class Wee_Logging_Block_Adminhtml_Index_Grid extends Mage_Adminhtml_Block_Widget_Grid
{ 
   /** * Constructor */ 
   public function __construct() 
   { 
      parent::__construct(); 
      $this->setId('loggingLogGrid'); 
      $this->setDefaultSort('time'); 
      $this->setDefaultDir('DESC'); 
      $this->setSaveParametersInSession(true); 
      $this->setUseAjax(true); 
   } 
   /** * PrepareCollection method. */ 
   protected function _prepareCollection() 
   { 
   	 $this->setCollection(Mage::getResourceModel('wee_logging/event_collection')); 
   	 return parent::_prepareCollection(); 
   } 
   /** * Return grids url */ 
   public function getGridUrl() 
   { 
	 return $this->getUrl('*/*/grid', array('_current' => true)); 
   } 
   /** * Grid URL * * @return string */ 
   public function getRowUrl($row) 
   { 
      return $this->getUrl('*/*/details', array('event_id'=>$row->getId())); 
   } 
   /** * Configuration of grid */ 
   protected function _prepareColumns() 
   { 
   	  $this->addColumn('time', 
   	  						array( 'header' => Mage::helper('wee_logging')->__('Time'), 
   	  								'index' => 'time', 
   	  								'type' => 'datetime', 
   	  								'width' => 160, )
   	  ); 
   	  $this->addColumn('event', array( 'header' => Mage::helper('wee_logging')->__('Action Group'), 
   	  								   'index' => 'event_code', 
   	  								   'type' => 'options', 
   	  								   'sortable' => false, 
   	  								   'options' => Mage::getSingleton('wee_logging/config')->getLabels(), )
   	  ); 
   	  $actions = array(); 
   	  foreach (Mage::getResourceSingleton('wee_logging/event')->getAllFieldValues('action') as $action) 
   	  { 
         $actions[$action] = $action; 
   	  } 
   	  $this->addColumn('action', 
   	  						array( 'header' => Mage::helper('wee_logging')->__('Action'), 
   	  						'index' => 'action', 
   	  						'type' => 'options', 
   	  						'options' => $actions, 
   	  						'sortable' => false, 
   	  						'width' => 75, )); 
   	  $this->addColumn('ip', array( 'header' => Mage::helper('wee_logging')->__('IP Address'), 
   	  								'index' => 'ip', 
   	  								'type' => 'text', 
   	  								'filter' => 'wee_logging/adminhtml_grid_filter_ip', 
   	  								'renderer' => 'adminhtml/widget_grid_column_renderer_ip', 
   	  								'sortable' => false, 'width' => 125, )); 
   	  $this->addColumn('user', array( 'header' => Mage::helper('wee_logging')->__('Username'), 
   	  								  'index' => 'user', 'type' => 'text', 
   	  								  'sortable' => false, 
   	  								  'filter' => 'wee_logging/adminhtml_grid_filter_user', 
   	  								  'width' => 150, )); 
   	  $this->addColumn('status', array( 'header' => Mage::helper('wee_logging')->__('Result'), 
   	  								    'index' => 'status', 
   	  								    'sortable' => false, 
   	  								    'type' => 'options', 
   	  								    'options' => array( wee_logging_Model_Event::RESULT_SUCCESS => Mage::helper('wee_logging')->__('Success'), 
   	  														wee_logging_Model_Event::RESULT_FAILURE => Mage::helper('wee_logging')->__('Failure'), ), 
   	  									'width' => 100, )); 
   	  $this->addColumn('fullaction', array( 'header' => Mage::helper('wee_logging')->__('Full Action Name'), 
   	  										   'index' => 'fullaction', 'sortable' => false, 'type' => 'text' )); 
   	  $this->addColumn('info', array( 'header' => Mage::helper('wee_logging')->__('Short Details'), 
   	  								  'index' => 'info', 
   	  								  'type' => 'text', 
   	  								  'sortable' => false, 
   	  								  'filter' => 'adminhtml/widget_grid_column_filter_text', 
   	  								  'renderer' => 'wee_logging/adminhtml_grid_renderer_details', 
   	  								  'width' => 100, )); 
   	  $this->addColumn('view', array( 'header' => Mage::helper('wee_logging')->__('Full Details'), 
   	  								  'width' => 50, 
   	  								  'type' => 'action', 
   	  								  'getter' => 'getId', 
   	  								  'actions' => array(array( 'caption' => Mage::helper('wee_logging')->__('View'), 
   	  								  							'url' => array( 'base' => '*/*/details', ), 
   	  								  							'field' => 'event_id' )), 
   	  								  'filter' => false, 
   	  								  'sortable' => false, )); 
   	  //$this->addExportType('*/*/exportCsv', 'CSV'); //$this->addExportType('*/*/exportXml', 'MSXML'); 
   	  return $this; 
   } 
}